
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>模板表达式的沙箱模型 · petite-vue源码剖析</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="^_^肥仔John">
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="2_reactivity_system/6_trigger_and_scheduler.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">前言</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    《Petite-Vue源码剖析》简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="0_intro/1_reason_for_source_reading.html">
            
                <a href="0_intro/1_reason_for_source_reading.html">
            
                    
                    为什么要读源码
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">在线渲染</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="1_online_rendering/0_intro.html">
            
                <a href="1_online_rendering/0_intro.html">
            
                    
                    章节介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="1_online_rendering/1_start_from_static_view.html">
            
                <a href="1_online_rendering/1_start_from_static_view.html">
            
                    
                    从静态视图首次渲染开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="1_online_rendering/2_initial_rendering_and_rerendering_for_v-if.html">
            
                <a href="1_online_rendering/2_initial_rendering_and_rerendering_for_v-if.html">
            
                    
                    条件v-if的首次渲染和重新渲染
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="1_online_rendering/3_initial_rendering_and_rerendering_for_v-for.html">
            
                <a href="1_online_rendering/3_initial_rendering_and_rerendering_for_v-for.html">
            
                    
                    循环v-for的首次渲染和重新渲染
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="1_online_rendering/4_directives/1_attribute_binding.html">
            
                <a href="1_online_rendering/4_directives/1_attribute_binding.html">
            
                    
                    属性绑定v-bind的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="1_online_rendering/4_directives/2_event_binding.html">
            
                <a href="1_online_rendering/4_directives/2_event_binding.html">
            
                    
                    事件绑定v-on的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="1_online_rendering/4_directives/3_bidirectional_binding.html">
            
                <a href="1_online_rendering/4_directives/3_bidirectional_binding.html">
            
                    
                    双向绑定v-model的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="1_online_rendering/4_directives/4_ref.html">
            
                <a href="1_online_rendering/4_directives/4_ref.html">
            
                    
                    特殊指令ref的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="1_online_rendering/5_tips_for_template.html">
            
                <a href="1_online_rendering/5_tips_for_template.html">
            
                    
                    优化手段template的原理和使用技巧
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">响应式系统</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="2_reactivity_system/0_intro.html">
            
                <a href="2_reactivity_system/0_intro.html">
            
                    
                    章节介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="2_reactivity_system/1_reactive_object_array.html">
            
                <a href="2_reactivity_system/1_reactive_object_array.html">
            
                    
                    逐行解读reactive如何构建对象和数组的响应式对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="2_reactivity_system/2_reactive_map_set.html">
            
                <a href="2_reactivity_system/2_reactive_map_set.html">
            
                    
                    逐行解读reactive如何构建Map和Set的响应式对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="2_reactivity_system/3_register_side_effect.html">
            
                <a href="2_reactivity_system/3_register_side_effect.html">
            
                    
                    逐行解读effect如何注册副作用函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="2_reactivity_system/4_cleanup_algorithm.html">
            
                <a href="2_reactivity_system/4_cleanup_algorithm.html">
            
                    
                    依赖清理优化算法详解-算法思路
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="2_reactivity_system/5_smi.html">
            
                <a href="2_reactivity_system/5_smi.html">
            
                    
                    依赖清理优化算法详解-基于JavaScript引擎的SMI进一步压榨性能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="2_reactivity_system/6_trigger_and_scheduler.html">
            
                <a href="2_reactivity_system/6_trigger_and_scheduler.html">
            
                    
                    逐行解读trigger和调度器
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">沙箱模型</li>
        
        
    
        <li class="chapter active" data-level="4.1" data-path="3_sandbox.html">
            
                <a href="3_sandbox.html">
            
                    
                    模板表达式的沙箱模型
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >模板表达式的沙箱模型</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x6A21;&#x677F;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x6C99;&#x7BB1;&#x6A21;&#x578B;"><b>1. </b>&#x6A21;&#x677F;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x6C99;&#x7BB1;&#x6A21;&#x578B;</a></li><ul><li><span class="title-icon "></span><a href="#&#x4EC0;&#x4E48;&#x662F;&#x6C99;&#x7BB1;"><b>1.1. </b>&#x4EC0;&#x4E48;&#x662F;&#x6C99;&#x7BB1;</a></li><li><span class="title-icon "></span><a href="#&#x539F;&#x751F;&#x6C99;&#x7BB1;-iframe"><b>1.2. </b>&#x539F;&#x751F;&#x6C99;&#x7BB1;-iframe</a></li><li><span class="title-icon "></span><a href="#&#x6C99;&#x7BB1;&#x7684;&#x6750;&#x6599;-withproxyevalnew-function"><b>1.3. </b>&#x6C99;&#x7BB1;&#x7684;&#x6750;&#x6599;-with+Proxy+eval/new Function</a></li><ul><li><span class="title-icon "></span><a href="#&#x4EC0;&#x4E48;&#x662F;with&#xFF1F;"><b>1.3.1. </b>&#x4EC0;&#x4E48;&#x662F;with&#xFF1F;</a></li><li><span class="title-icon "></span><a href="#&#x5982;&#x4F55;&#x5229;&#x7528;proxy&#x9632;&#x6B62;&#x7ED1;&#x5B9A;&#x89E3;&#x6790;&#x9003;&#x9038;&#xFF1F;"><b>1.3.2. </b>&#x5982;&#x4F55;&#x5229;&#x7528;Proxy&#x9632;&#x6B62;&#x7ED1;&#x5B9A;&#x89E3;&#x6790;&#x9003;&#x9038;&#xFF1F;</a></li><li><span class="title-icon "></span><a href="#&#x90AA;&#x6076;&#x7684;eval"><b>1.3.3. </b>&#x90AA;&#x6076;&#x7684;eval</a></li><li><span class="title-icon "></span><a href="#new-function"><b>1.3.4. </b>new Function</a></li></ul><li><span class="title-icon "></span><a href="#&#x6C99;&#x7BB1;&#x9003;&#x9038;sandbox-escape"><b>1.4. </b>&#x6C99;&#x7BB1;&#x9003;&#x9038;(Sandbox Escape)</a></li><ul><li><span class="title-icon "></span><a href="#&#x901A;&#x8FC7;&#x539F;&#x578B;&#x94FE;&#x5B9E;&#x73B0;&#x9003;&#x9038;"><b>1.4.1. </b>&#x901A;&#x8FC7;&#x539F;&#x578B;&#x94FE;&#x5B9E;&#x73B0;&#x9003;&#x9038;</a></li><li><span class="title-icon "></span><a href="#symbolunscopables"><b>1.4.2. </b>Symbol.unscopables</a></li></ul><li><span class="title-icon "></span><a href="#&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x5B89;&#x5168;&#x7684;&#x6C99;&#x7BB1;"><b>1.5. </b>&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x5B89;&#x5168;&#x7684;&#x6C99;&#x7BB1;</a></li><li><span class="title-icon "></span><a href="#&#x5C0F;&#x7ED3;"><b>1.6. </b>&#x5C0F;&#x7ED3;</a></li></ul></ul></div><h1 id="&#x6A21;&#x677F;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x6C99;&#x7BB1;&#x6A21;&#x578B;"><a name="&#x6A21;&#x677F;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x6C99;&#x7BB1;&#x6A21;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x6A21;&#x677F;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x6C99;&#x7BB1;&#x6A21;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x6A21;&#x677F;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x6C99;&#x7BB1;&#x6A21;&#x578B;</h1>
<p>&#x5728;&#x89E3;&#x6790;<code>v-if</code>&#x548C;<code>v-for</code>&#x7B49;&#x6307;&#x4EE4;&#x65F6;&#x6211;&#x4EEC;&#x4F1A;&#x770B;&#x5230;&#x901A;&#x8FC7;<code>evaluate</code>&#x6267;&#x884C;&#x6307;&#x4EE4;&#x503C;&#x4E2D;&#x7684;JavaScript&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x800C;&#x4E14;&#x80FD;&#x591F;&#x8BFB;&#x53D6;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x4E0A;&#x7684;&#x5C5E;&#x6027;&#x3002;&#x800C;<code>evaluate</code>&#x7684;&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">const</span> evalCache: Record&lt;<span class="hljs-built_in">string</span>, <span class="hljs-built_in">Function</span>&gt; = <span class="hljs-built_in">Object</span>.create(<span class="hljs-literal">null</span>)

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> evaluate = (scope: <span class="hljs-built_in">any</span>, exp: <span class="hljs-built_in">string</span>, el?: Node) =&gt;
  execute(scope, <span class="hljs-string">`return(<span class="hljs-subst">${exp}</span>)`</span>, el)

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> execute = (scope: <span class="hljs-built_in">any</span>, exp: <span class="hljs-built_in">string</span>, el?: Node) =&gt; {
  <span class="hljs-keyword">const</span> fn = evalCache[exp] || (evalCache[exp] = toFunction(exp))
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">return</span> fn(scope, el)
  } <span class="hljs-keyword">catch</span> (e) {
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">import</span>.meta.env.DEV) {
      <span class="hljs-built_in">console</span>.warn(<span class="hljs-string">`Error when evaluating expression &quot;<span class="hljs-subst">${exp}</span>&quot;:`</span>)
    }
    <span class="hljs-built_in">console</span>.error(e)
  }
}

<span class="hljs-keyword">const</span> toFunction = (exp: <span class="hljs-built_in">string</span>): <span class="hljs-built_in">Function</span> =&gt; {
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(<span class="hljs-string">`$data`</span>, <span class="hljs-string">`$el`</span>, <span class="hljs-string">`with($data){<span class="hljs-subst">${exp}</span>}`</span>)
  } <span class="hljs-keyword">catch</span> (e) {
    <span class="hljs-built_in">console</span>.error(<span class="hljs-string">`<span class="hljs-subst">${(e as Error).message}</span> in expression: <span class="hljs-subst">${exp}</span>`</span>)
    <span class="hljs-keyword">return</span> () =&gt; {}
  }
}
</code></pre>
<p>&#x7B80;&#x5316;&#x4E3A;&#x5982;&#x4E0B;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> evaluate = (scope: <span class="hljs-built_in">any</span>, exp: <span class="hljs-built_in">string</span>, el?: Node) =&gt; {
  <span class="hljs-keyword">return</span> (<span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(<span class="hljs-string">`$data`</span>, <span class="hljs-string">`$el`</span>, <span class="hljs-string">`with($data){return(<span class="hljs-subst">${exp}</span>)}`</span>))(scope, el)
}
</code></pre>
<p>&#x800C;&#x8FD9;&#x91CC;&#x5C31;&#x662F;&#x901A;&#x8FC7;<code>with</code>+<code>new Function</code>&#x6784;&#x5EFA;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x6C99;&#x7BB1;&#xFF0C;&#x4E3A;<code>v-if</code>&#x548C;<code>v-for</code>&#x6307;&#x4EE4;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x53EF;&#x63A7;&#x7684;JavaScript&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x6267;&#x884C;&#x73AF;&#x5883;&#x3002;</p>
<h2 id="&#x4EC0;&#x4E48;&#x662F;&#x6C99;&#x7BB1;"><a name="&#x4EC0;&#x4E48;&#x662F;&#x6C99;&#x7BB1;" class="anchor-navigation-ex-anchor" href="#&#x4EC0;&#x4E48;&#x662F;&#x6C99;&#x7BB1;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x4EC0;&#x4E48;&#x662F;&#x6C99;&#x7BB1;</h2>
<p>&#x6C99;&#x7BB1;(Sandbox)&#x4F5C;&#x4E3A;&#x4E00;&#x79CD;&#x5B89;&#x5168;&#x673A;&#x5236;&#xFF0C;&#x7528;&#x4E8E;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x53EF;&#x63A7;&#x7684;&#x6267;&#x884C;&#x73AF;&#x5883;&#x4F9B;&#x672A;&#x7ECF;&#x6D4B;&#x8BD5;&#x6216;&#x4E0D;&#x53D7;&#x4FE1;&#x4EFB;&#x7684;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#xFF0C;&#x5E76;&#x4E14;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x6C61;&#x67D3;&#x5916;&#x90E8;&#x7A0B;&#x5E8F;&#x7684;&#x6267;&#x884C;&#x73AF;&#x5883;(&#x5982;&#x7BE1;&#x6539;/&#x52AB;&#x6301;window&#x5BF9;&#x8C61;&#x53CA;&#x5176;&#x5C5E;&#x6027;)&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5916;&#x90E8;&#x7A0B;&#x5E8F;&#x7684;&#x8FD0;&#x884C;&#x3002;</p>
<p>&#x4E0E;&#x6B64;&#x540C;&#x65F6;&#xFF0C;&#x6C99;&#x7BB1;&#x548C;&#x5916;&#x90E8;&#x7A0B;&#x5E8F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x9884;&#x671F;&#x7684;&#x65B9;&#x5F0F;&#x8FDB;&#x884C;&#x901A;&#x4FE1;&#x3002;</p>
<p>&#x66F4;&#x7EC6;&#x5316;&#x7684;&#x529F;&#x80FD;&#x5C31;&#x662F;:</p>
<ol>
<li>&#x62E5;&#x6709;&#x72EC;&#x7ACB;&#x7684;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x548C;&#x5168;&#x5C40;&#x5BF9;&#x8C61;(<code>window</code>)</li>
<li>&#x6C99;&#x7BB1;&#x63D0;&#x4F9B;&#x542F;&#x52A8;&#x3001;&#x6682;&#x505C;&#x3001;&#x6062;&#x590D;&#x548C;&#x505C;&#x673A;&#x529F;&#x80FD;</li>
<li>&#x591A;&#x53F0;&#x6C99;&#x7BB1;&#x652F;&#x6301;&#x5E76;&#x884C;&#x8FD0;&#x884C;</li>
<li>&#x6C99;&#x7BB1;&#x548C;&#x4E3B;&#x73AF;&#x5883;&#x3001;&#x6C99;&#x7BB1;&#x548C;&#x6C99;&#x7BB1;&#x4E4B;&#x95F4;&#x53EF;&#x5B9E;&#x73B0;&#x5B89;&#x5168;&#x901A;&#x4FE1;</li>
</ol>
<h2 id="&#x539F;&#x751F;&#x6C99;&#x7BB1;-iframe"><a name="&#x539F;&#x751F;&#x6C99;&#x7BB1;-iframe" class="anchor-navigation-ex-anchor" href="#&#x539F;&#x751F;&#x6C99;&#x7BB1;-iframe"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x539F;&#x751F;&#x6C99;&#x7BB1;-iframe</h2>
<p><code>iframe</code>&#x62E5;&#x6709;&#x72EC;&#x7ACB;&#x7684;browser context&#xFF0C;&#x4E0D;&#x5355;&#x5355;&#x63D0;&#x4F9B;&#x72EC;&#x7ACB;&#x7684;JavaScript&#x6267;&#x884C;&#x73AF;&#x5883;&#xFF0C;&#x751A;&#x81F3;&#x8FD8;&#x62E5;&#x6709;&#x72EC;&#x7ACB;&#x7684;HTML&#x548C;CSS&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x3002;</p>
<p>&#x901A;&#x8FC7;&#x5C06;<code>iframe</code>&#x7684;<code>src</code>&#x8BBE;&#x7F6E;&#x4E3A;<code>about:blank</code>&#x5373;&#x4FDD;&#x8BC1;&#x540C;&#x6E90;&#x4E14;&#x4E0D;&#x4F1A;&#x53D1;&#x751F;&#x8D44;&#x6E90;&#x52A0;&#x8F7D;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>iframe.contentWindow</code>&#x83B7;&#x53D6;&#x4E0E;&#x4E3B;&#x73AF;&#x5883;&#x72EC;&#x7ACB;&#x7684;window&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x6C99;&#x7BB1;&#x7684;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x901A;&#x8FC7;<code>with</code>&#x5C06;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x8F6C;&#x6362;&#x4E3A;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
<p>&#x800C;<code>iframe</code>&#x7684;&#x7F3A;&#x70B9;&#xFF1A;</p>
<ol>
<li>&#x82E5;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;JavaScript&#x6267;&#x884C;&#x73AF;&#x5883;&#xFF0C;&#x90A3;&#x4E48;&#x5176;&#x5B83;&#x7279;&#x6027;&#x5219;&#x4E0D;&#x4EC5;&#x4EC5;&#x662F;&#x7D2F;&#x8D58;&#xFF0C;&#x8FD8;&#x4F1A;&#x5E26;&#x6765;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x6027;&#x80FD;&#x5F00;&#x9500;&#x3002;&#x800C;&#x4E14;<code>iframe</code>&#x4F1A;&#x5BFC;&#x81F4;&#x4E3B;&#x89C6;&#x7A97;&#x7684;onload&#x4E8B;&#x4EF6;&#x5EF6;&#x8FDF;&#x6267;&#x884C;&#xFF1B;</li>
<li>&#x5185;&#x90E8;&#x7A0B;&#x5E8F;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x6D4F;&#x89C8;&#x5668;&#x6240;&#x6709;API&#xFF0C;&#x6211;&#x4EEC;&#x65E0;&#x6CD5;&#x63A7;&#x5236;&#x767D;&#x540D;&#x5355;&#x3002;(&#x8FD9;&#x4E2A;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;Proxy&#x5904;&#x7406;)</li>
</ol>
<h2 id="&#x6C99;&#x7BB1;&#x7684;&#x6750;&#x6599;-withproxyevalnew-function"><a name="&#x6C99;&#x7BB1;&#x7684;&#x6750;&#x6599;-withproxyevalnew-function" class="anchor-navigation-ex-anchor" href="#&#x6C99;&#x7BB1;&#x7684;&#x6750;&#x6599;-withproxyevalnew-function"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x6C99;&#x7BB1;&#x7684;&#x6750;&#x6599;-with+Proxy+eval/new Function</h2>
<h3 id="&#x4EC0;&#x4E48;&#x662F;with&#xFF1F;"><a name="&#x4EC0;&#x4E48;&#x662F;with&#xFF1F;" class="anchor-navigation-ex-anchor" href="#&#x4EC0;&#x4E48;&#x662F;with&#xFF1F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.1. &#x4EC0;&#x4E48;&#x662F;with&#xFF1F;</h3>
<p>JavaScript&#x91C7;&#x7528;&#x7684;&#x662F;&#x8BED;&#x6CD5;&#x4F5C;&#x7528;&#x57DF;&#xFF08;&#x6216;&#x79F0;&#x4E3A;&#x9759;&#x6001;&#x4F5C;&#x7528;&#x57DF;&#xFF09;&#xFF0C;&#x800C;<code>with</code>&#x5219;&#x8BA9;JavaScript&#x62E5;&#x6709;&#x90E8;&#x5206;&#x52A8;&#x6001;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x7279;&#x6027;&#x3002;</p>
<p><code>with(obj)</code>&#x4F1A;&#x5C06;<code>obj</code>&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x65B0;&#x7684;&#x4E34;&#x65F6;&#x4F5C;&#x7528;&#x57DF;&#x6DFB;&#x52A0;&#x5230;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x94FE;&#x7684;&#x9876;&#x7AEF;&#xFF0C;&#x90A3;&#x4E48;<code>obj</code>&#x7684;&#x5C5E;&#x6027;&#x5C06;&#x4F5C;&#x4E3A;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x7ED1;&#x5B9A;&#xFF0C;&#x4F46;&#x662F;&#x548C;&#x666E;&#x901A;&#x7684;&#x7ED1;&#x5B9A;&#x89E3;&#x6790;&#x4E00;&#x6837;&#xFF0C;&#x82E5;&#x5728;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x65E0;&#x6CD5;&#x89E3;&#x6790;&#x5219;&#x4F1A;&#x5411;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#x67E5;&#x627E;&#xFF0C;&#x76F4;&#x5230;&#x6839;&#x4F5C;&#x7528;&#x57DF;&#x4E5F;&#x65E0;&#x6CD5;&#x89E3;&#x6790;&#x4E3A;&#x6B62;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> foo = <span class="hljs-string">&apos;lexical scope&apos;</span>
<span class="hljs-keyword">let</span> bar = <span class="hljs-string">&apos;lexical scope&apos;</span>

;(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// &#x8BBF;&#x95EE;&#x8BED;&#x53E5;&#x6E90;&#x7801;&#x4E66;&#x5199;&#x7684;&#x4F4D;&#x7F6E;&#x51B3;&#x5B9A;&#x8FD9;&#x91CC;&#x8BBF;&#x95EE;&#x7684;foo&#x6307;&#x5411;&apos;lexical scope&apos;</span>
  <span class="hljs-built_in">console</span>.log(foo)
})()
<span class="hljs-comment">// &#x56DE;&#x663E; lexical scope</span>

;(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">dynamicScope</span>) </span>{
  <span class="hljs-keyword">with</span>(dynamicScope) {
    <span class="hljs-comment">/**
     * &#x9ED8;&#x8BA4;&#x8BBF;&#x95EE;&#x8BED;&#x53E5;&#x6E90;&#x7801;&#x4E66;&#x5199;&#x7684;&#x4F4D;&#x7F6E;&#x51B3;&#x5B9A;&#x8FD9;&#x91CC;&#x8BBF;&#x95EE;&#x7684;foo&#x6307;&#x5411;&apos;lexical scope&apos;&#xFF0C;
     * &#x4F46;&#x7531;&#x4E8E;&#x8BE5;&#x8BED;&#x53E5;&#x4F4D;&#x4E8E;with&#x7684;&#x8BED;&#x53E5;&#x4F53;&#x4E2D;&#xFF0C;&#x56E0;&#x6B64;&#x5C06;&#x6539;&#x53D8;&#x89E3;&#x6790;foo&#x7ED1;&#x5B9A;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x3002;
     */</span> 
    <span class="hljs-built_in">console</span>.log(foo)
    <span class="hljs-comment">// &#x7531;&#x4E8E;with&#x521B;&#x5EFA;&#x7684;&#x4E34;&#x65F6;&#x4F5C;&#x7528;&#x57DF;&#x4E2D;&#x6CA1;&#x6709;&#x5B9A;&#x4E49;bar&#xFF0C;&#x56E0;&#x6B64;&#x4F1A;&#x5411;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#x67E5;&#x627E;&#x89E3;&#x6790;&#x7ED1;&#x5B9A;</span>
    <span class="hljs-built_in">console</span>.log(bar)
  }
})({
  foo: <span class="hljs-string">&apos;dynamic scope&apos;</span>
})
<span class="hljs-comment">// &#x56DE;&#x663E; dynamic scope</span>
<span class="hljs-comment">// &#x56DE;&#x663E; lexical scope</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF1A;<code>with</code>&#x521B;&#x5EFA;&#x7684;&#x662F;&#x4E34;&#x65F6;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x548C;&#x901A;&#x8FC7;&#x51FD;&#x6570;&#x521B;&#x5EFA;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x662F;&#x4E0D;&#x540C;&#x7684;&#x3002;&#x5177;&#x4F53;&#x8868;&#x73B0;&#x4E3A;&#x5F53;<code>with</code>&#x4E2D;&#x8C03;&#x7528;&#x5916;&#x90E8;&#x5B9A;&#x4E49;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x90A3;&#x4E48;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x8BBF;&#x95EE;&#x7ED1;&#x5B9A;&#x65F6;&#xFF0C;&#x7531;&#x4E8E;&#x7531;<code>with</code>&#x521B;&#x5EFA;&#x7684;&#x4E34;&#x65F6;&#x4F5C;&#x7528;&#x57DF;&#x5C06;&#x88AB;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x66FF;&#x4EE3;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#x800C;&#x5B58;&#x5728;&#xFF0C;&#x5BFC;&#x81F4;&#x65E0;&#x6CD5;&#x8BBF;&#x95EE;<code>with</code>&#x521B;&#x5EFA;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x4E2D;&#x7684;&#x7ED1;&#x5B9A;&#x3002;&#x8FD9;&#x4E5F;&#x662F;&#x4E3A;&#x4F55;&#x8BF4;<code>with</code>&#x8BA9;JavaScript&#x62E5;&#x6709;&#x90E8;&#x5206;&#x52A8;&#x6001;&#x4F5C;&#x7528;&#x57DF;&#x7279;&#x6027;&#x7684;&#x539F;&#x56E0;&#x4E86;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> foo = <span class="hljs-string">&apos;lexical scope&apos;</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">showFoo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(foo)
}

;(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">dynamicScope</span>) </span>{
  <span class="hljs-keyword">with</span>(dynamicScope) {
    showFoo()
  }
})({
  foo: <span class="hljs-string">&apos;dynamic scope&apos;</span>
})
<span class="hljs-comment">// &#x56DE;&#x663E; lexical scope</span>
</code></pre>
<p>&#x518D;&#x4E00;&#x6B21;&#x6CE8;&#x610F;&#xFF1A;&#x82E5;&#x51FD;&#x6570;&#x662F;&#x5728;<code>with</code>&#x521B;&#x5EFA;&#x7684;&#x4E34;&#x65F6;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x5B9A;&#x4E49;&#x7684;&#xFF0C;&#x90A3;&#x4E48;&#x5C06;&#x4EE5;&#x8BE5;&#x4E34;&#x65F6;&#x4F5C;&#x7528;&#x57DF;&#x4F5C;&#x4E3A;&#x7236;&#x4F5C;&#x7528;&#x57DF;</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> foo = <span class="hljs-string">&apos;lexical scope&apos;</span>

;(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">dynamicScope</span>) </span>{
  <span class="hljs-keyword">with</span>(dynamicScope) {
    (() =&gt; {
      <span class="hljs-keyword">const</span> bar = <span class="hljs-string">&apos;bar&apos;</span>
      <span class="hljs-built_in">console</span>.log(bar)
      <span class="hljs-comment">// &#x5176;&#x5B9E;&#x8FD9;&#x91CC;&#x5C31;&#x662F;&#x91C7;&#x7528;&#x8BED;&#x6CD5;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x8C01;&#x53EB;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x7684;&#x4F4D;&#x7F6E;&#x5728;&#x4E34;&#x65F6;&#x4F5C;&#x7528;&#x57DF;&#x751F;&#x6548;&#x7684;&#x5730;&#x65B9;&#x5462;&#x3002;</span>
      <span class="hljs-built_in">console</span>.log(foo)
    })()
  }
})({
  foo: <span class="hljs-string">&apos;dynamic scope&apos;</span>
})
<span class="hljs-comment">// &#x56DE;&#x663E; bar</span>
<span class="hljs-comment">// &#x56DE;&#x663E; dynamic scope</span>
</code></pre>
<p>&#x53E6;&#x5916;&#xFF0C;&#x5728;<em>ESM&#x6A21;&#x5F0F;</em>&#x6216;<em>strict&#x6A21;&#x5F0F;</em>(&#x4F7F;&#x7528;<code>class</code>&#x5B9A;&#x4E49;&#x7C7B;&#x4F1A;&#x542F;&#x52A8;&#x542F;&#x7528;<em>strict&#x6A21;&#x5F0F;</em>)&#x4E0B;&#x90FD;&#x7981;&#x6B62;&#x4F7F;&#x7528;<code>with</code>&#x8BED;&#x53E5;&#x54E6;&#xFF01;</p>
<ul>
<li><code>Error: With statements cannot be used in an ECMAScript module</code></li>
<li><code>Uncaught SyntaxError: Strict mode code may not include a with statement</code></li>
</ul>
<p>&#x4F46;&#x65E0;&#x6CD5;&#x963B;&#x6B62;&#x901A;&#x8FC7;<code>eval</code>&#x6216;<code>new Function</code>&#x6267;&#x884C;<code>with</code>&#x54E6;&#xFF01;</p>
<h3 id="&#x5982;&#x4F55;&#x5229;&#x7528;proxy&#x9632;&#x6B62;&#x7ED1;&#x5B9A;&#x89E3;&#x6790;&#x9003;&#x9038;&#xFF1F;"><a name="&#x5982;&#x4F55;&#x5229;&#x7528;proxy&#x9632;&#x6B62;&#x7ED1;&#x5B9A;&#x89E3;&#x6790;&#x9003;&#x9038;&#xFF1F;" class="anchor-navigation-ex-anchor" href="#&#x5982;&#x4F55;&#x5229;&#x7528;proxy&#x9632;&#x6B62;&#x7ED1;&#x5B9A;&#x89E3;&#x6790;&#x9003;&#x9038;&#xFF1F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2. &#x5982;&#x4F55;&#x5229;&#x7528;Proxy&#x9632;&#x6B62;&#x7ED1;&#x5B9A;&#x89E3;&#x6790;&#x9003;&#x9038;&#xFF1F;</h3>
<p>&#x901A;&#x8FC7;&#x524D;&#x9762;&#x6570;&#x7BC7;&#x6587;&#x7AE0;&#x7684;&#x4ECB;&#x7ECD;&#xFF0C;&#x6211;&#x60F3;&#x5927;&#x5BB6;&#x5BF9;<code>Proxy</code>&#x5DF2;&#x7ECF;&#x4E0D;&#x518D;&#x964C;&#x751F;&#x4E86;&#x3002;&#x4E0D;&#x8FC7;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x4F1A;&#x7528;&#x5230;&#x4E4B;&#x524D;&#x4E00;&#x7B14;&#x5E26;&#x8FC7;&#x7684;<code>has</code>&#x62E6;&#x622A;&#x5668;&#xFF0C;&#x7528;&#x4E8E;&#x62E6;&#x622A;<code>with</code>&#x4EE3;&#x7801;&#x4E2D;&#x4EFB;&#x610F;&#x53D8;&#x91CF;&#x7684;&#x8BBF;&#x95EE;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x53EF;&#x6B63;&#x5E38;&#x5728;&#x4F5C;&#x7528;&#x57DF;&#x94FE;&#x67E5;&#x627E;&#x7684;&#x7ED1;&#x5B9A;&#x767D;&#x540D;&#x5355;&#xFF0C;&#x800C;&#x767D;&#x540D;&#x5355;&#x5916;&#x7684;&#x5219;&#x5FC5;&#x987B;&#x4EE5;&#x6C99;&#x7BB1;&#x521B;&#x5EFA;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x4E0A;&#x5B9A;&#x4E49;&#x7EF4;&#x62A4;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> whiteList = [<span class="hljs-string">&apos;Math&apos;</span>, <span class="hljs-string">&apos;Date&apos;</span>, <span class="hljs-string">&apos;console&apos;</span>]
<span class="hljs-keyword">const</span> createContext = (ctx) =&gt; {
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Proxy</span>(ctx, {
    has(target, key) {
      <span class="hljs-comment">// &#x7531;&#x4E8E;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;`with`&#x7684;&#x53C2;&#x6570;&#x6210;&#x4E3A;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;&#x82E5;&#x8FD4;&#x56DE;false&#x5219;&#x4F1A;&#x7EE7;&#x7EED;&#x5F80;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#x67E5;&#x627E;&#x89E3;&#x6790;&#x7ED1;&#x5B9A;</span>
      <span class="hljs-keyword">if</span> (whiteList.includes(key)) {
        <span class="hljs-keyword">return</span> target.hasOwnProperty(key)
      }

      <span class="hljs-comment">// &#x8FD4;&#x56DE;true&#x5219;&#x4E0D;&#x4F1A;&#x5F80;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#x7EE7;&#x7EED;&#x67E5;&#x627E;&#x89E3;&#x6790;&#x7ED1;&#x5B9A;&#xFF0C;&#x4F46;&#x5B9E;&#x9645;&#x4E0A;&#x6CA1;&#x6709;&#x5BF9;&#x5E94;&#x7684;&#x7ED1;&#x5B9A;&#xFF0C;&#x5219;&#x4F1A;&#x8FD4;&#x56DE;undefined&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x62A5;&#x9519;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;&#x624B;&#x52A8;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x3002;</span>
      <span class="hljs-keyword">if</span> (!targe.hasOwnProperty(key)) {
        <span class="hljs-keyword">throw</span> <span class="hljs-built_in">ReferenceError</span>(<span class="hljs-string">`<span class="hljs-subst">${key}</span> is not defined`</span>)
      }

      <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
    }
  })
}

<span class="hljs-keyword">with</span>(createContext({ foo: <span class="hljs-string">&apos;foo&apos;</span> })) {
  <span class="hljs-built_in">console</span>.log(foo)
  <span class="hljs-built_in">console</span>.log(bar)
}
<span class="hljs-comment">// &#x56DE;&#x663E; foo</span>
<span class="hljs-comment">// &#x629B;&#x51FA; `Uncaught ReferenceError: bar is not defined`</span>
</code></pre>
<p>&#x5230;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#xFF0C;&#x6211;&#x4EEC;&#x867D;&#x7136;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x53EF;&#x7528;&#x6C99;&#x7BB1;&#x6A21;&#x578B;&#xFF0C;&#x4F46;&#x81F4;&#x547D;&#x7684;&#x662F;&#x65E0;&#x6CD5;&#x5C06;&#x5916;&#x90E8;&#x7A0B;&#x5E8F;&#x4EE3;&#x7801;&#x4F20;&#x9012;&#x6C99;&#x7BB1;&#x4E2D;&#x6267;&#x884C;&#x3002;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x901A;&#x8FC7;<code>eval</code>&#x548C;<code>new Function</code>&#x6765;&#x5B9E;&#x73B0;&#x3002;</p>
<h3 id="&#x90AA;&#x6076;&#x7684;eval"><a name="&#x90AA;&#x6076;&#x7684;eval" class="anchor-navigation-ex-anchor" href="#&#x90AA;&#x6076;&#x7684;eval"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.3. &#x90AA;&#x6076;&#x7684;eval</h3>
<p><code>eval()</code>&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x6267;&#x884C;&#x5B57;&#x7B26;&#x4E32;&#x5F62;&#x5F0F;&#x7684;JavaScript&#x4EE3;&#x7801;&#xFF0C;&#x5176;&#x4E2D;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;<em>&#x95ED;&#x5305;&#x4F5C;&#x7528;&#x57DF;</em>&#x53CA;&#x5176;<em>&#x7236;&#x4F5C;&#x7528;&#x57DF;</em>&#x76F4;&#x5230;<em>&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;</em>&#x7ED1;&#x5B9A;&#xFF0C;&#x8FD9;&#x4F1A;&#x5F15;&#x8D77;&#x4EE3;&#x7801;&#x6CE8;&#x5165;(code injection)&#x7684;&#x5B89;&#x5168;&#x95EE;&#x9898;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> bar = <span class="hljs-string">&apos;bar&apos;</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">run</span>(<span class="hljs-params">arg, script</span>) </span>{
  ;(() =&gt; {
    <span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;foo&apos;</span>
    <span class="hljs-built_in">eval</span>(script)
  })()
}

<span class="hljs-keyword">const</span> script = <span class="hljs-string">`
  console.log(arg)
  console.log(bar)
  console.log(foo)
`</span>
run(<span class="hljs-string">&apos;hi&apos;</span>, script)
<span class="hljs-comment">// &#x56DE;&#x663E; hi</span>
<span class="hljs-comment">// &#x56DE;&#x663E; bar </span>
<span class="hljs-comment">// &#x56DE;&#x663E; foo</span>
</code></pre>
<h3 id="new-function"><a name="new-function" class="anchor-navigation-ex-anchor" href="#new-function"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.4. new Function</h3>
<p>&#x76F8;&#x5BF9;<code>eval</code>&#xFF0C;<code>new Function</code>&#x7684;&#x7279;&#x70B9;&#x662F;:</p>
<ol>
<li><code>new Funciton</code>&#x51FD;&#x6570;&#x4F53;&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#x53EA;&#x80FD;&#x8BBF;&#x95EE;<em>&#x51FD;&#x6570;&#x5165;&#x53C2;</em>&#x548C;<em>&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;</em>&#x7684;&#x7ED1;&#x5B9A;&#xFF1B;</li>
<li>&#x5C06;&#x52A8;&#x6001;&#x811A;&#x672C;&#x7A0B;&#x5E8F;&#x89E3;&#x6790;&#x5E76;&#x5B9E;&#x4F8B;&#x5316;&#x4E3A;&#x51FD;&#x6570;&#x5BF9;&#x8C61;&#xFF0C;&#x540E;&#x7EED;&#x4E0D;&#x7528;&#x518D;&#x91CD;&#x65B0;&#x89E3;&#x6790;&#x5C31;&#x53EF;&#x4EE5;&#x81F3;&#x76F4;&#x63A5;&#x6267;&#x884C;&#xFF0C;&#x6027;&#x80FD;&#x6BD4;<code>eval</code>&#x597D;&#x3002;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> bar = <span class="hljs-string">&apos;bar&apos;</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">run</span>(<span class="hljs-params">arg, script</span>) </span>{
  ;(() =&gt; {
    <span class="hljs-keyword">const</span> foo = <span class="hljs-string">&apos;foo&apos;</span>
    ;(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(<span class="hljs-string">&apos;arg&apos;</span>, script))(arg)
  })()
}

<span class="hljs-keyword">const</span> script = <span class="hljs-string">`
  console.log(arg)
  console.log(bar)
  console.log(foo)
`</span>
run(<span class="hljs-string">&apos;hi&apos;</span>, script)
<span class="hljs-comment">// &#x56DE;&#x663E; hi</span>
<span class="hljs-comment">// &#x56DE;&#x663E; bar </span>
<span class="hljs-comment">// &#x56DE;&#x663E; Uncaught ReferenceError: foo is not defined</span>
</code></pre>
<h2 id="&#x6C99;&#x7BB1;&#x9003;&#x9038;sandbox-escape"><a name="&#x6C99;&#x7BB1;&#x9003;&#x9038;sandbox-escape" class="anchor-navigation-ex-anchor" href="#&#x6C99;&#x7BB1;&#x9003;&#x9038;sandbox-escape"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. &#x6C99;&#x7BB1;&#x9003;&#x9038;(Sandbox Escape)</h2>
<p>&#x6C99;&#x7BB1;&#x9003;&#x9038;&#x5C31;&#x662F;&#x6C99;&#x7BB1;&#x5185;&#x8FD0;&#x884C;&#x7684;&#x7A0B;&#x5E8F;&#x4EE5;&#x975E;&#x5408;&#x6CD5;&#x7684;&#x65B9;&#x5F0F;&#x8BBF;&#x95EE;&#x6216;&#x4FEE;&#x6539;&#x5916;&#x90E8;&#x7A0B;&#x5E8F;&#x7684;&#x6267;&#x884C;&#x73AF;&#x5883;&#x6216;&#x5F71;&#x54CD;&#x5916;&#x90E8;&#x7A0B;&#x5E8F;&#x7684;&#x6B63;&#x5E38;&#x6267;&#x884C;&#x3002;
&#x867D;&#x7136;&#x4E0A;&#x9762;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x901A;&#x8FC7;Proxy&#x63A7;&#x5236;&#x6C99;&#x7BB1;&#x5185;&#x90E8;&#x7A0B;&#x5E8F;&#x53EF;&#x8BBF;&#x95EE;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x94FE;&#xFF0C;&#x4F46;&#x4ECD;&#x7136;&#x6709;&#x4E0D;&#x5C11;&#x7A81;&#x7834;&#x6C99;&#x7BB1;&#x7684;&#x6F0F;&#x6D1E;&#x3002;</p>
<h3 id="&#x901A;&#x8FC7;&#x539F;&#x578B;&#x94FE;&#x5B9E;&#x73B0;&#x9003;&#x9038;"><a name="&#x901A;&#x8FC7;&#x539F;&#x578B;&#x94FE;&#x5B9E;&#x73B0;&#x9003;&#x9038;" class="anchor-navigation-ex-anchor" href="#&#x901A;&#x8FC7;&#x539F;&#x578B;&#x94FE;&#x5B9E;&#x73B0;&#x9003;&#x9038;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4.1. &#x901A;&#x8FC7;&#x539F;&#x578B;&#x94FE;&#x5B9E;&#x73B0;&#x9003;&#x9038;</h3>
<p>JavaScript&#x4E2D;constructor&#x5C5E;&#x6027;&#x6307;&#x5411;&#x521B;&#x5EFA;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x800C;&#x8BE5;&#x5C5E;&#x6027;&#x662F;&#x5B58;&#x5728;&#x4E8E;&#x539F;&#x578B;&#x4E2D;&#xFF0C;&#x5E76;&#x4E14;&#x662F;&#x4E0D;&#x53EF;&#x9760;&#x7684;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Test</span>(<span class="hljs-params"></span>)</span>{}
<span class="hljs-keyword">const</span> obj = <span class="hljs-keyword">new</span> Test()

<span class="hljs-built_in">console</span>.log(obj.hasOwnProperty(<span class="hljs-string">&apos;constructor&apos;</span>)) <span class="hljs-comment">// false</span>
<span class="hljs-built_in">console</span>.log(obj.__proto__.hasOwnProperty(<span class="hljs-string">&apos;constructor&apos;</span>)) <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x9003;&#x9038;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5728;&#x6C99;&#x7BB1;&#x5185;&#x6267;&#x884C;&#x5982;&#x4E0B;&#x4EE3;&#x7801;</span>
({}).constructor.prototype.toString = () =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Escape!&apos;</span>)
}

<span class="hljs-comment">// &#x5916;&#x90E8;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x73AF;&#x5883;&#x88AB;&#x6C61;&#x67D3;&#x4E86;</span>
<span class="hljs-built_in">console</span>.log(({}).toString()) 
<span class="hljs-comment">// &#x56DE;&#x663E; Escape!</span>
<span class="hljs-comment">// &#x800C;&#x671F;&#x5F85;&#x56DE;&#x663E;&#x662F; [object Object]</span>
</code></pre>
<h3 id="symbolunscopables"><a name="symbolunscopables" class="anchor-navigation-ex-anchor" href="#symbolunscopables"><i class="fa fa-link" aria-hidden="true"></i></a>1.4.2. Symbol.unscopables</h3>
<p><code>Symbol.unscopables</code>&#x4F5C;&#x4E3A;&#x5C5E;&#x6027;&#x540D;&#x5BF9;&#x5E94;&#x7684;&#x5C5E;&#x6027;&#x503C;&#x8868;&#x793A;&#x8BE5;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;<code>with</code>&#x53C2;&#x6570;&#x65F6;&#xFF0C;&#x54EA;&#x4E9B;&#x5C5E;&#x6027;&#x4F1A;&#x88AB;with&#x73AF;&#x5883;&#x6392;&#x9664;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span>]
<span class="hljs-built_in">console</span>.log(arr[<span class="hljs-built_in">Symbol</span>.unscopables])
<span class="hljs-comment">// &#x56DE;&#x663E; {&quot;copyWithin&quot;:true,&quot;entries&quot;:true,&quot;fill&quot;:true,&quot;find&quot;:true,&quot;findIndex&quot;:true,&quot;flat&quot;:true,&quot;flatMap&quot;:true,&quot;includes&quot;:true,&quot;keys&quot;:true,&quot;values&quot;:true,&quot;at&quot;:true,&quot;findLast&quot;:true,&quot;findLastIndex&quot;:true}</span>

<span class="hljs-keyword">with</span>(arr) {
  <span class="hljs-built_in">console</span>.log(entries) <span class="hljs-comment">// &#x629B;&#x51FA;ReferenceError</span>
}

<span class="hljs-keyword">const</span> includes = <span class="hljs-string">&apos;&#x6210;&#x529F;&#x9003;&#x9038;&#x5566;&apos;</span>
<span class="hljs-keyword">with</span>(arr) {
  <span class="hljs-built_in">console</span>.log(includes) <span class="hljs-comment">// &#x56DE;&#x663E; &#x6210;&#x529F;&#x9003;&#x9038;&#x5566;</span>
}
</code></pre>
<p>&#x9632;&#x8303;&#x7684;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x901A;&#x8FC7;Proxy&#x7684;get&#x62E6;&#x622A;&#x5668;&#xFF0C;&#x5F53;&#x8BBF;&#x95EE;<code>Symbol.unscopables</code>&#x65F6;&#x8FD4;&#x56DE;undefined</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> createContext = (ctx) =&gt; {
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Proxy</span>(ctx, {
    has(target, key) {
      <span class="hljs-comment">// &#x7531;&#x4E8E;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;`with`&#x7684;&#x53C2;&#x6570;&#x6210;&#x4E3A;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;&#x82E5;&#x8FD4;&#x56DE;false&#x5219;&#x4F1A;&#x7EE7;&#x7EED;&#x5F80;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#x67E5;&#x627E;&#x89E3;&#x6790;&#x7ED1;&#x5B9A;</span>
      <span class="hljs-keyword">if</span> (whiteList.includes(key)) {
        <span class="hljs-keyword">return</span> target.hasOwnProperty(key)
      }

      <span class="hljs-comment">// &#x8FD4;&#x56DE;true&#x5219;&#x4E0D;&#x4F1A;&#x5F80;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#x7EE7;&#x7EED;&#x67E5;&#x627E;&#x89E3;&#x6790;&#x7ED1;&#x5B9A;&#xFF0C;&#x4F46;&#x5B9E;&#x9645;&#x4E0A;&#x6CA1;&#x6709;&#x5BF9;&#x5E94;&#x7684;&#x7ED1;&#x5B9A;&#xFF0C;&#x5219;&#x4F1A;&#x8FD4;&#x56DE;undefined&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x62A5;&#x9519;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;&#x624B;&#x52A8;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x3002;</span>
      <span class="hljs-keyword">if</span> (!targe.hasOwnProperty(key)) {
        <span class="hljs-keyword">throw</span> <span class="hljs-built_in">ReferenceError</span>(<span class="hljs-string">`<span class="hljs-subst">${key}</span> is not defined`</span>)
      }

      <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
    },
    get(target, key, receiver) {
      <span class="hljs-keyword">if</span> (key === <span class="hljs-built_in">Symbol</span>.unscopables) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">undefined</span>
      }

      <span class="hljs-keyword">return</span> <span class="hljs-built_in">Reflect</span>.get(target, key, receiver)
    }
  })
}
</code></pre>
<h2 id="&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x5B89;&#x5168;&#x7684;&#x6C99;&#x7BB1;"><a name="&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x5B89;&#x5168;&#x7684;&#x6C99;&#x7BB1;" class="anchor-navigation-ex-anchor" href="#&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x5B89;&#x5168;&#x7684;&#x6C99;&#x7BB1;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. &#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x5B89;&#x5168;&#x7684;&#x6C99;&#x7BB1;</h2>
<pre><code class="lang-ts"><span class="hljs-keyword">const</span> toFunction = (script: <span class="hljs-built_in">string</span>): <span class="hljs-built_in">Function</span> =&gt; {
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(<span class="hljs-string">&apos;ctx&apos;</span>, <span class="hljs-string">`with(ctx){<span class="hljs-subst">${script}</span>}`</span>)
  } <span class="hljs-keyword">catch</span> (e) {
    <span class="hljs-built_in">console</span>.error(<span class="hljs-string">`<span class="hljs-subst">${(e as Error).message}</span> in script: <span class="hljs-subst">${script}</span>`</span>)
    <span class="hljs-keyword">return</span> () =&gt; {}
  }
}

<span class="hljs-keyword">const</span> toProxy = (ctx: object, whiteList: <span class="hljs-built_in">string</span>[]) =&gt; {
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Proxy(ctx, {
    has(target, key) {
      <span class="hljs-comment">// &#x7531;&#x4E8E;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;`with`&#x7684;&#x53C2;&#x6570;&#x6210;&#x4E3A;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;&#x82E5;&#x8FD4;&#x56DE;false&#x5219;&#x4F1A;&#x7EE7;&#x7EED;&#x5F80;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#x67E5;&#x627E;&#x89E3;&#x6790;&#x7ED1;&#x5B9A;</span>
      <span class="hljs-keyword">if</span> (whiteList.includes(key)) {
        <span class="hljs-keyword">return</span> target.hasOwnProperty(key)
      }

      <span class="hljs-comment">// &#x8FD4;&#x56DE;true&#x5219;&#x4E0D;&#x4F1A;&#x5F80;&#x7236;&#x4F5C;&#x7528;&#x57DF;&#x7EE7;&#x7EED;&#x67E5;&#x627E;&#x89E3;&#x6790;&#x7ED1;&#x5B9A;&#xFF0C;&#x4F46;&#x5B9E;&#x9645;&#x4E0A;&#x6CA1;&#x6709;&#x5BF9;&#x5E94;&#x7684;&#x7ED1;&#x5B9A;&#xFF0C;&#x5219;&#x4F1A;&#x8FD4;&#x56DE;undefined&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x62A5;&#x9519;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;&#x624B;&#x52A8;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x3002;</span>
      <span class="hljs-keyword">if</span> (!targe.hasOwnProperty(key)) {
        <span class="hljs-keyword">throw</span> <span class="hljs-built_in">ReferenceError</span>(<span class="hljs-string">`<span class="hljs-subst">${key}</span> is not defined`</span>)
      }

      <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
    },
    <span class="hljs-keyword">get</span>(target, key, receiver) {
      <span class="hljs-keyword">if</span> (key === Symbol.unscopables) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">undefined</span>
      }

      <span class="hljs-keyword">return</span> Reflect.get(target, key, receiver)
    }
  })
}

<span class="hljs-keyword">class</span> Sandbox {
  <span class="hljs-keyword">private</span> evalCache: Map&lt;<span class="hljs-built_in">string</span>, <span class="hljs-built_in">Function</span>&gt;
  <span class="hljs-keyword">private</span> ctxCache: WeakMap&lt;object, Proxy&gt;

  <span class="hljs-keyword">constructor</span>(private whiteList: string[] = [&apos;Math&apos;, &apos;Date&apos;, &apos;console&apos;]) {
    <span class="hljs-keyword">this</span>.evalCache = <span class="hljs-keyword">new</span> Map&lt;<span class="hljs-built_in">string</span>, <span class="hljs-built_in">Function</span>&gt;()
    <span class="hljs-keyword">this</span>.ctxCache = <span class="hljs-keyword">new</span> WeakMap&lt;object, Proxy&gt;()
  }

  run(script: <span class="hljs-built_in">string</span>, ctx: object) {
    <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.evalCache.has(script)) {
      <span class="hljs-keyword">this</span>.evalCache.set(script, toFunction(script))
    }
    <span class="hljs-keyword">const</span> fn = <span class="hljs-keyword">this</span>.evalCache.get(script)

    <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.ctxCache.has(ctx)) {
      <span class="hljs-keyword">this</span>.ctxCache.set(ctx, toProxy(ctx, <span class="hljs-keyword">this</span>.whiteList))
    }
    <span class="hljs-keyword">const</span> ctxProxy = <span class="hljs-keyword">this</span>.ctxCache.get(ctx)

    <span class="hljs-keyword">return</span> fn(ctx)
}
</code></pre>
<p>&#x5230;&#x6B64;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x5B89;&#x5168;&#x7684;&#x6C99;&#x7BB1;&#x6A21;&#x578B;&#xFF0C;&#x4F46;&#x8FDC;&#x8FDC;&#x8FD8;&#x6CA1;&#x8FBE;&#x5230;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4F7F;&#x7528;&#x7684;&#x8981;&#x6C42;&#x3002;</p>
<h2 id="&#x5C0F;&#x7ED3;"><a name="&#x5C0F;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x5C0F;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>1.6. &#x5C0F;&#x7ED3;</h2>
<p>&#x4E0A;&#x8FF0;&#x6211;&#x4EEC;&#x662F;&#x901A;&#x8FC7;Proxy&#x963B;&#x6B62;&#x6C99;&#x7BB1;&#x5185;&#x7684;&#x7A0B;&#x5E8F;&#x8BBF;&#x95EE;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x82E5;&#x6CA1;&#x6709;Proxy&#x90A3;&#x4E48;&#x8981;&#x600E;&#x6837;&#x5904;&#x7406;&#x5462;&#xFF1F;&#x53E6;&#x5916;&#xFF0C;&#x5982;&#x4F55;&#x5B9E;&#x73B0;&#x6C99;&#x7BB1;&#x7684;&#x542F;&#x505C;&#x3001;&#x6062;&#x590D;&#x548C;&#x5E76;&#x884C;&#x8FD0;&#x884C;&#x5462;&#xFF1F;&#x5176;&#x5B9E;&#x8FD9;&#x4E2A;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x770B;&#x8682;&#x8681;&#x91D1;&#x670D;&#x7684;&#x5FAE;&#x524D;&#x7AEF;&#x6846;&#x67B6;qiankun(&#x4E7E;&#x5764;)&#x662F;&#x5982;&#x4F55;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x5177;&#x4F53;&#x5185;&#x5BB9;&#x8BF7;&#x671F;&#x5F85;&#x540E;&#x7EED;&#x7684;&#x300A;&#x5FAE;&#x524D;&#x7AEF;&#x6846;&#x67B6;qiankun&#x6E90;&#x7801;&#x5256;&#x6790;&#x300B;&#x5427;&#xFF01;</p>
<script type="text/javascript">
  /**
   * Donation
   */
  function showQR(){
    var rewardButton = document.getElementById('rewardButton')
    var qr = document.getElementById('QR')
    if (rewardButton) {
      rewardButton.style.display = 'none'
    }
    if (qr) {
      qr.style.display = 'block'
    }
  }
  setInterval(showQR, 1000)

  /**
   * Baidu analysis
   */
  var _hmt = _hmt || [];
  (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?8bca1e3aa362a7f85dbe8304cff65225";
    var s = document.getElementsByTagName("script")[0]; 
    s.parentNode.insertBefore(hm, s);
  })();
</script>


<footer class="page-footer"><span class="copyright">Copyright &#xA9; fsjohnhuang 2022 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">File Modify: 
2022-04-26 09:45:19
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="2_reactivity_system/6_trigger_and_scheduler.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 逐行解读trigger和调度器">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"模板表达式的沙箱模型","level":"4.1","depth":1,"previous":{"title":"逐行解读trigger和调度器","level":"3.7","depth":1,"path":"2_reactivity_system/6_trigger_and_scheduler.md","ref":"2_reactivity_system/6_trigger_and_scheduler.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-sharing","theme-comscore","search-pro","code","back-to-top-button","tbfed-pagefooter","chapter-fold","expandable-chapters","splitter","anchor-navigation-ex","donate","sharing-plus","baidu"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy fsjohnhuang 2022"},"chapter-fold":{},"splitter":{},"search-pro":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"code":{"copyButtons":true},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赞赏","title":"","wechat":"/petite-vue-source-reading/images/wechat.jpg","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":true},"theme-comscore":{},"back-to-top-button":{},"baidu":{"token":"8bca1e3aa362a7f85dbe8304cff65225"},"sharing":{"qq":false,"all":["qq","qzone","weibo","whatsapp","twitter","facebook","line"],"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"^_^肥仔John","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"","variables":{},"title":"petite-vue源码剖析","gitbook":"*","description":""},"file":{"path":"3_sandbox.md","mtime":"2022-04-26T01:45:19.599Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-05-05T01:20:11.998Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-baidu/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

